<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="2"><div >订单编号</div></el-col>
      <el-col :span="2"><div >病人姓名</div></el-col>
      <el-col :span="6"><div >病症描述</div></el-col>
      <!--<el-col :span="4"><div >选择科室</div></el-col>-->
      <!--<el-col :span="4"><div >选择医生</div></el-col>-->
      <el-col :span="3"><div >操作</div></el-col>
    </el-row>
    <hr>
      <div class="wrap_item" v-for="order in orinfo" >
        <el-row :gutter="20">
          <el-col :span="2"><div >{{order.id}}</div></el-col>
          <el-col :span="2"><div >{{order.patientname}}</div></el-col>
          <el-col :span="6"><div >{{order.symptom}}</div></el-col>
          <el-col :span="3"><div><el-button  @click="Detail(order.id)">选择医生</el-button>
            <el-dialog title="医生回复" :visible.sync="dialogFormVisible" width="450px">
              <el-form :model="form">
                <el-form-item label="科室" :label-width="formLabelWidth">
                  <el-select v-model="value" placeholder="请选择" @focus="selectTy()">
                    <el-option
                      v-for="item in tyinfo"
                      :key="item.tyname"
                      :label="item.tyname"
                      :value="item.tyname">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="医生" :label-width="formLabelWidth">
                  <el-select v-model="value1" placeholder="请选择" @focus="selectDoctor()">
                    <el-option
                      v-for="item in dcinfo"
                      :key="item.name"
                      :label="item.name"
                      :value="item.name">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="toDetail" >确 定</el-button>
              </div>
            </el-dialog></div></el-col>
          <!--<el-col :span="4">-->
            <!--<el-select v-model="value" placeholder="请选择" @focus="selectTy()">-->
              <!--<el-option-->
                <!--v-for="item in tyinfo"-->
                <!--:key="item.tyname"-->
                <!--:label="item.tyname"-->
                <!--:value="item.tyname">-->
              <!--</el-option>-->
            <!--</el-select>-->
          <!--</el-col>-->
          <!--<el-col :span="4">-->
            <!--<el-select v-model="value1" placeholder="请选择" @focus="selectDoctor()">-->
              <!--<el-option-->
                <!--v-for="item in dcinfo"-->
                <!--:key="item.name"-->
                <!--:label="item.name"-->
                <!--:value="item.name">-->
              <!--</el-option>-->
            <!--</el-select>-->
          <!--</el-col>-->
          <!--<el-col :span="6"><el-button type="primary" @click="Detail(order.id)">选择医生</el-button></el-col>-->
        </el-row>
        <hr>
    </div>
  </div>
</template>

<script>
  export default {
    name: "product",
    data() {
      return{
        orinfo: [],
        option: [],
        tyinfo: [],
        dcinfo: [],
        form: {
          value: '',
          value1: '',
        },
        value: '',
        value1: '',
        formLabelWidth: '80px',
        dialogFormVisible: false,
      }
    },
    methods: {
          getList: function () {
            this.$ajax.get('http://47.75.110.31:8080/orinfo/findByStatus?status=0')
              .then(response => {
                this.orinfo = response.data;
              })
          },
          Detail (orderid) {
            this.dialogFormVisible = true;
            localStorage.setItem("orderId",orderid);
            console.log(orderid);
          },
          selectTy(){
            this.$ajax.get('http://47.75.110.31:8080/tyinfo/findAll')
              .then(response => {
                this.tyinfo = response.data;
                console.log(this.tyinfo[0].tyname)
              })
          },
          selectDoctor(){
            this.$ajax.get('http://47.75.110.31:8080/dcinfo/findByType?type='+this.value)
              .then(response => {
                this.dcinfo = response.data;
                console.log(this.tyinfo[0].tyname)
              })
          },
          toDetail () {
            var orderId = localStorage.getItem("orderId");
            console.log(orderId)
              this.updatedc(orderId);
              if(this.value1===''){
                alert('请选择医生姓名')
              }
              this.$ajax.post('http://47.75.110.31:8080/orinfo/updatedoctor?id='+orderId+'&doctor='+this.value1,
                {

                  headers: {
                    'Content-Type': 'application/json;charset=UTF-8'
                  }
                }
              ).then(response => {
                console.log(response.data);
                if (response.data === "success") {
                  this.$message({
                    message: '恭喜你添加成功',
                    type: 'success'
                  });
                  location.reload();
                }
              })
          },
        updatedc(orderId){
          this.$ajax.post('http://47.75.110.31:8080/orinfo/updatestatus?status=1&id='+orderId,
            {
              headers: {
                'Content-Type': 'application/json;charset=UTF-8'
              }
            }
          ).then(response => {
          })
        }
        },
      mounted () {
        this.getList()
    }
  }

</script>

<style scoped>

</style>
